package com.lgj.springboot_lgj.web.controller;


import com.github.pagehelper.PageInfo;
import com.lgj.springboot_lgj.bean.basic.Comment;
import com.lgj.springboot_lgj.service.impl.CommentServiceImpl;
import com.lgj.springboot_lgj.utils.Result;
import com.lgj.springboot_lgj.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "评论模块")
@RestController
@RequestMapping("/auth/comment")
public  class CommentController {

    @Autowired
    private CommentServiceImpl service;
    @ApiOperation("审核评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "comment_id",value = "评论id",required = true),
            @ApiImplicitParam(name = "comment_status",value = "审核状态",required = true)
    })
    @PutMapping("/check")
    public Result checkComment(Integer id,Integer status){
        //调用service

        service.checkComment(id,status);
        return ResultUtil.success("审核成功");
    }


    @ApiOperation("分页查询所有评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true),
            @ApiImplicitParam(name = "keyWords",value = "评论关键字",required = true)
    })

    @GetMapping("/pageQuery")
    public  Result pageQuery(int pageNum, int pageSize, String keyWords){
        PageInfo<Comment> commentPageInfo = service.pageQuery(pageNum, pageSize, keyWords);
        return ResultUtil.success(commentPageInfo);
    }
    @ApiOperation("批量删除评论")
    @DeleteMapping("/batchDelete")
    public  Result batchDelete(int[] ids){
        System.out.println("-------------------------");
        service.batchDelete(ids);
        return ResultUtil.success("删除成功");
    }


    @ApiOperation("根据id删除信息")
    @ApiImplicitParam(name = "id",value = "评论id",required = true,dataType = "int")
    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        //调用service层方法
        service.deleteById(id);
        //将处理结果响应给前端
        return ResultUtil.success("删除成功");
    }
}